<template>
  <div class="login">
    <div class="login-container">
      <div class="login-wrap">
          <div class="login-left">
            <img src="../../assets/images/logo.png" alt="">
          </div>
          <div class="login-border">
            <div class="login-main">
             <h1>登录</h1>
             <el-form ref="loginForm" :rules="rules" :model="loginForm" label-width="100px">
              <el-form-item label="用户名" prop="username">
                <el-input
                 class="input"
                  placeholder="请输入用户名"
                  size="small"
                  v-model="loginForm.username"
                  @focus="focusUsername()"
                  >
                   <i slot="prefix" class="el-input__icon el-icon-user"></i>
                    
                    <span slot="suffix" v-if="isClose" @click="clear()">
                      <i class="icon iconfont icon-close"></i>
                     </span>
                </el-input>
              </el-form-item>
                <el-form-item label="密码" prop="password">
                <el-input
                  class="input"
                  placeholder="请输入密码"
                  size="small"
                  show-password
                  v-model="loginForm.password">
                   <i slot="prefix" class="icon iconfont icon-mima"></i>
                </el-input>
              </el-form-item>
              <el-form-item>
                 <el-button class="login-btn" type="primary" @click="handleLogin('loginForm')" plain size="small">登录</el-button>
              </el-form-item>
             </el-form>
            </div>
          </div>
      </div>
    </div>
    <div class="login-footer">
      AGPL v3 Licensed | Copyright © 2020-present Fizz
      <p>
        <a href="https://beian.miit.gov.cn/#/Integrated/index" target="blank">粤ICP备19131807号 </a>
       | <img src="../../assets/images/beian.png">
        <a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=44060502002317"  target="blank">
          粤公网安备 44060502002317号
        </a>
      </p>
    </div>
  </div>
</template>
<script>
export default {
  name: 'Login',
  data() {
    return {
        loginForm: {
           username:'',
           password: '',
        },
        isClose: false,
        rules: {
          username: [
            { required: true, message: '请输入用户名称', trigger: 'blur' },
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' },
          ],
        }
    }
  },
  methods: {
    focusUsername() {
      this.isClose = true;
    },
    // 登录
    handleLogin(loginForm) {
        this.$refs[loginForm].validate((valid) => {
          if(valid)  {
            this.$router.push('/home');
          }else {
             console.log('error submit!!');
             return false;
          }
        })
    },
    // 清空用户名
    clear() {
      this.loginForm.username = '';
    },
     submit () {
          this.$message.success('当前数据'+JSON.stringify(this.obj));
      },
  }
}

</script>
<style lang="scss" scoped>
.login {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
  .login-container {
    width: 100%;
    height: 854px;
    border: 1px solid #fff;
}
.login-wrap {
    margin: 100px auto;
    width: 946px;
    height: 603px;
    background-color: #fff;
    padding: 12px;
    border: 1px solid #dcdfe6;
    border-radius: 37px;
    .login-left {
      float: left;
      position: relative;
      width: 486px;
      min-height: 500px;
      height: 100%;
      background: linear-gradient(312deg,#3c76ff,#7760fb);
      img {
        width: 310px;
        height: 240px;
        position: absolute;
        top: 50%;
        left: 50%;
        margin-top: -120px;
        margin-left: -155px;
      }
    }
    .login-border {
      position: relative;
      float: left;
      width: 460px;
      min-height: 500px;
      height: 100%;
      .login-main {
        width: 300px;
        height: 386px;
        position: absolute;
        top: 50%;
        left: 50%;
        margin-left: -150px;
        margin-top: -230px;
        h1 {
          margin: 45px 0;
        }
        
        .login-btn {
          margin-top: 20px;
          width: 240px;
          margin-left: -40px;
        }
      }
    }
}
.login-footer {
  width: 100%;
  height: 60px;
  padding: 10px;
  font-size: 12px;
  color: #494c54;
  font-weight: 400;
  p {
    margin: 10px 0;
    img {
      vertical-align: bottom;
    }
    a {
      text-decoration: none;
      color: #494c54;
    }
  }
}
</style>
